#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef double ll;
typedef long long lld;
const int NN = (2 << 20) + 9, MM = 255;
char s[NN], op[MM], filename[MM], cmtname[MM], mergee[MM];
int n;
map<string, string> mp;
map<string, map<string, string>> history;
int zzq_empty = 1;
int main()
{
    scanf("%d", &n);
    fgets(s, NN, stdin);
    for (; n--;)
    {
        fgets(s, NN, stdin);
        sscanf(s, "%s", op);
        if (!strcmp(op, "write"))
        {
            int offset, len;
            sscanf(s, "%s%s%d%d", op, filename, &offset, &len);
            fgets(s, NN, stdin);
            string &str = mp[filename];
            if (str.size() < offset + len)
                str.resize(offset + len, '.');
            copy(s, s + len, str.begin() + offset);
            zzq_empty = 0;
        }
        else if (!strcmp(op, "read"))
        {
            int offset, len;
            sscanf(s, "%s%s%d%d", op, filename, &offset, &len);
            if (!mp.count(filename))
            {
                for (int i = 0; i < len; ++i)
                    printf(".");
                printf("\n");
                continue;
            }
            string &str = mp[filename];
            if (str.size() < offset)
            {
                for (int i = 0; i < len; ++i)
                    printf(".");
                printf("\n");
                continue;
            }
            if (str.size() < offset + len)
            {
                for (int i = offset; i < str.size(); ++i)
                    printf("%c", str[i]);
                for (int i = str.size() - offset; i < len; ++i)
                    printf(".");
                printf("\n");
                continue;
            }
            for (int i = 0; i < len; ++i)
                printf("%c", str[offset + i]);
            printf("\n");
        }
        else if (!strcmp(op, "ls"))
        {
            if (mp.empty())
            {
                printf("0\n");
                continue;
            }
            printf("%d %s %s\n", (int)mp.size(), mp.begin()->first.c_str(), mp.rbegin()->first.c_str());
        }
        else if (!strcmp(op, "unlink"))
        {
            sscanf(s, "%s%s", op, filename);
            mp.erase(filename);
            zzq_empty = 0;
        }
        else if (!strcmp(op, "commit"))
        {
            sscanf(s, "%s%s", op, cmtname);
            if (zzq_empty || history.count(cmtname))
                continue;
            //history[cmtname] = mp;
        }
        else if (!strcmp(op, "checkout"))
        {
            sscanf(s, "%s%s", op, cmtname);
            if (!zzq_empty || !history.count(cmtname))
                continue;
            //mp = history[cmtname];
        }
        else if (!strcmp(op, "merge"))
        {
            sscanf(s, "%s%s%s", op, mergee, cmtname);
            if (!zzq_empty)
                continue;
        }
    }
}
